<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>文章列表</title>
		<%@ include file="../../../common/Admin-list.jsp"%>
		
		<link rel="stylesheet" type="text/css" href="<%=bpath %>Scripts/ztree/zTreeStyle.css" />		
		<script type="text/javascript" src="<%=bpath %>Scripts/ztree/jquery.ztree.all-3.5.js"></script>
	</head>
<body>
<div class="easyui-panel" fit="true" type="panel" border="false">
	<div class="easyui-layout" data-options="fit:true,border:false" type="layout">
		<div data-options="region:'west',split:true,border:false" style="width:200px;">
			<div class="treelist module">
				<div class="hd">
					<h2 class="t">组织机构</h2>
					<span class="handle4tree" title="显示/隐藏树列表"></span>					
				</div>
				<div class="bd">
					<div id="valleyTree" class="ztree"></div>
				</div>
			</div>
		</div>
		
		<div data-options="region:'center',split:true,border:false">
			<iframe id="configPage" name="configPage" src=" " frameborder="0" width="100%" height="100%" allowTransparency></iframe>
		</div>
		<div id="win"></div>
	</div>
</div>
<script type="text/javascript">
	
	//加载左侧树
	var setting = {
		async : {
			enable : true,
			url :'../district/getzTreeNodes.json?pid=3607',
			autoParam : [ 'id=pid', 'level' ],//异步加载时需要自动提交父节点属性的参数 ../district/findByPidAll.json?isCounty=yes
			//otherParam: { 'type' : 'area','site_type':'AA01'}, //区域 空气站 'site_type':'AA01,WM01,WM02'
			dataFilter : zTreefilter
		},
		check: {
			enable: true,
			autoCheckTrigger: true,
			chkboxType: { "Y": "ps", "N": "ps" }
		},		
		view : {
			//addHoverDom: addHoverDom,//当用户鼠标移动到节点上时,显示用户自定义控件,显示隐藏状态同zTree内部的编辑，删除按钮  
	      //  removeHoverDom: removeHoverDom//移出节点时,显示隐藏状态同zTree内部的编辑、删除按钮
		},
		callback : {
			//onDblClick: zTreeOnDbClick//双击节点			
			onCheck: zTreeOnCheck ,//选中的时候 
			onClick: zTreeOnClick,	
			onAsyncSuccess: onAsyncSuccess
			
		}
	};
		
	function zTreefilter(treeId, parentNode, childNodes) {
		if (!childNodes)
			return null;
		else {
			for (var i = 0, l = childNodes.length; i < l; i++) {
				if (childNodes[i].type=="0") {
					childNodes[i].icon="<%=bpath %>Scripts/ztree/img/diy/8.png";				
				}else if (childNodes[i].type=="1"){
					childNodes[i].icon="<%=bpath %>Scripts/ztree/img/diy/1_close.png";	
				}else{
					//treeNode.children.length
					childNodes[i].halfCheck = true;					
				}
			}			
			return childNodes;
		}		
	}	
	
	//加载成功后 
	var firstAsyncSuccessFlag = 0;
	function onAsyncSuccess(event, treeId, treeNode, msg) {			
		var zTree = $.fn.zTree.getZTreeObj(treeId);		
		//加载 展开 子节点
		var node=zTree.getNodeByParam("isParent",true,null); //如有多个节点满足查询条件，只返回第一个匹配到的节点 
		zTree.expandNode(node,true,true,true);	
		
		if(treeNode.children.length!=0){
			treeNode.halfCheck = false; // 取消 Halfcheck			
			var nodes = treeNode.children; //获得当前节点的子节点			
			//遍历每一个子节点更新其选中状态	
			for(var i = 0;i<nodes.length;i++){		
				zTree.checkNode(nodes[i],treeNode.checked,true,true);	
			}						
		}else{
			treeNode.checked=false;		
			zTree.setChkDisabled(treeNode, true); //没有站点 则禁用
		}		
	}
	
	var map = {}; //站点code	
	function zTreeOnCheck(event, treeId, treeNode) {		
		var treeObj = $.fn.zTree.getZTreeObj(treeId);		
		//展开当前节点 触发异步请求子节点的动作		
		treeObj.expandNode(treeNode,true,true,true);	
	  // alert(treeNode.id + ", " + treeNode.name + "," + treeNode.checked+","+treeNode.type);
		if(treeNode.type!="2"){ //如果是选中了 站点，则添加到 左侧的页面中
			if(treeNode.checked){		    	
		    	map[treeNode.id] = treeNode.name; //添加进入map site-code		    
		   	}else{ //取消选择
		    	if(!!map[treeNode.id]){
		    		delete map[treeNode.id];
		    	}		    	
		   	}
	        
		  	var i=0;var myArray=new Array(); var OrgIdArray=new Array();
			for(var prop in map){
			    if(map.hasOwnProperty(prop)){
			       myArray[i]=map[prop];
			       OrgIdArray[i]=prop; //map中key			       
			       i++;
			    }
			}		  
		    $(window.frames["configPage"].document).find("#orgid").val(OrgIdArray.join());
	  }	    	       
	    
	};		
	
	
	function zTreeOnClick(event, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj(treeId);
		if (treeNode.isParent) {
			zTree.expandNode(treeNode);
		} else {
			zTree.checkNode(treeNode,null,true,true);			
		}		
	}	
	
	//页面加载 
	$(function() {		
		var type=${data.type}; 		
		if(type=="0"){ //投稿统计
			var value="../ArticleList/chartAudit.htm?type=0";
			$("#configPage").attr("src",value);			
		}else if(type=="1"){//科室发稿统计
			var value="../ArticleList/chartAudit.htm?type=1";
			$("#configPage").attr("src",value);			
			setting.async.url='../district/getzTreeNodes.json?pid=3607&level=0';
		}		
			
		$.fn.zTree.init($('#valleyTree'), setting);		
	});
	
	
</script>
</body>
</html>